$(function () {
    var getParams = getArgs();
    window.currentHotel = getParams.hotel;
    var originalHref = $('#doc-header a').attr('href');
    $('#doc-header a').attr('href', originalHref + '?hotel=' + window.currentHotel);
    var originalHref = $('.back-mian a').attr('href');
    $('.back-mian a').attr('href', originalHref + '?hotel=' + window.currentHotel);

    $('#register-container').inputValidate({
        submit: {
            query: '#requestSubmit'
        },
        inputs: [{
            query: '#requestMobile',
            regexp: window.commonRegexp.mobile.regexp,
            message: window.commonRegexp.mobile.message,
            emptyMessage: window.commonRegexp.mobile.emptyMessage
        }, {
            query: '#requestVerifiedCode',
            regexp: window.commonRegexp.imageCode.regexp,
            message: window.commonRegexp.imageCode.message,
            emptyMessage: window.commonRegexp.imageCode.emptyMessage
        }]
    });
    $('#requestSubmit').on('successSubmit.amos.inputValidate', function (e) {
        var submitBtn = $(this);
        var params = {};
        params.mobile = $('#requestMobile').val();
        params.imageCode = $('#requestVerifiedCode').val();
        params.areaCode = $('.areaCodeValue').text().trim();
        toggleLoading(true);
        ajaxRequest('/Home/Public/checkRegister', params, 'post', function (data) {
            toggleLoading(false);
            timeoutForward('/Home/PublicPage/setpassword?hotel=' + window.currentHotel+'&val='+params.mobile+'&code='+params.areaCode, 1000);
        }, function (error, obj, defaultErrorHandler) {
            toggleLoading(false);
            defaultErrorHandler(error, obj);
            $('#imgcode').trigger('click');
        }, submitBtn);
    });
    // 是否同意服务协议
    $('#is-agree-protocal').on('click', function (e) {
        var mobile = $('#requestMobile').val();
        var imageCode = $('#requestVerifiedCode').val();
        if ((!$(this).is(':checked')) || mobile == '' || imageCode == '') {
            $('#requestSubmit').attr('disabled', true);
        }else {
            $('#requestSubmit').removeAttr('disabled');
        }
    });
    $('#register-container').bind('input propertychange',function(){
        var mobile = $('#requestMobile').val();
        var imageCode = $('#requestVerifiedCode').val();
        var checkout = $('#is-agree-protocal');
        if(mobile && imageCode && (checkout.is(':checked')) ){
            $('#requestSubmit').attr('disabled', false);          
        }else{
            $('#requestSubmit').attr('disabled', true);           
        }
    });
});
